{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周知识——柱状图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基本柱状图绘制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1004\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1004\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1004\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1004\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1004\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 垂直柱状图\n",
    "- 绘制方法\n",
    "> vbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('top', 4), ('x', 3)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"806f57e3-d620-4f0e-8479-e1fa21e4a621\" data-root-id=\"1005\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"e3c7a387-e9f0-4864-905e-3d4c80ca98ea\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1014\"}],\"center\":[{\"id\":\"1017\"},{\"id\":\"1021\"}],\"left\":[{\"id\":\"1018\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1039\"}],\"title\":{\"id\":\"1042\"},\"toolbar\":{\"id\":\"1029\"},\"x_range\":{\"id\":\"1006\"},\"x_scale\":{\"id\":\"1010\"},\"y_range\":{\"id\":\"1008\"},\"y_scale\":{\"id\":\"1012\"}},\"id\":\"1005\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"},{\"id\":\"1025\"},{\"id\":\"1026\"},{\"id\":\"1027\"}]},\"id\":\"1029\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1025\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1026\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1048\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"1036\"}},\"id\":\"1040\",\"type\":\"CDSView\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1042\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data\":{\"top\":[1,2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1047\"},\"selection_policy\":{\"id\":\"1048\"}},\"id\":\"1036\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"1046\"},\"ticker\":{\"id\":\"1015\"}},\"id\":\"1014\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1038\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1014\"},\"ticker\":null},\"id\":\"1017\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1037\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1015\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"1036\"},\"glyph\":{\"id\":\"1037\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1038\"},\"selection_glyph\":null,\"view\":{\"id\":\"1040\"}},\"id\":\"1039\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1046\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1018\"},\"dimension\":1,\"ticker\":null},\"id\":\"1021\",\"type\":\"Grid\"},{\"attributes\":{\"overlay\":{\"id\":\"1028\"}},\"id\":\"1024\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1006\",\"type\":\"DataRange1d\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1028\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1010\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1008\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1027\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1044\"},\"ticker\":{\"id\":\"1019\"}},\"id\":\"1018\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1047\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"WheelZoomTool\"}],\"root_ids\":[\"1005\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"e3c7a387-e9f0-4864-905e-3d4c80ca98ea\",\"root_ids\":[\"1005\"],\"roots\":{\"1005\":\"806f57e3-d620-4f0e-8479-e1fa21e4a621\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1005"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p= figure(plot_width = 400, plot_height = 400)\n",
    "# 绘制柱状图\n",
    "p.vbar(x=[1,2,3],\n",
    "       width=0.5,\n",
    "       bottom=0,\n",
    "       top=[1,2,2.5,3.7],\n",
    "       color=\"red\"\n",
    ")\n",
    "# 展示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method vbar in module bokeh.plotting.figure:\n",
      "\n",
      "vbar(x, width, top, bottom=0, *, fill_alpha=1.0, fill_color='gray', hatch_alpha=1.0, hatch_color='black', hatch_extra={}, hatch_pattern=None, hatch_scale=12.0, hatch_weight=1.0, line_alpha=1.0, line_cap='butt', line_color='black', line_dash=[], line_dash_offset=0, line_join='bevel', line_width=1, name=None, tags=[], **kwargs) method of bokeh.plotting.figure.Figure instance\n",
      "    Configure and add :class:`~bokeh.models.glyphs.VBar` glyphs to this Figure.\n",
      "    \n",
      "    Args:\n",
      "        x (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The x-coordinates of the centers of the vertical bars.\n",
      "    \n",
      "        width (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The widths of the vertical bars.\n",
      "    \n",
      "        top (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the top edges.\n",
      "    \n",
      "        bottom (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the bottom edges.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "    \n",
      "    Keyword args:\n",
      "        fill_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The fill alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        fill_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The fill color values for the vertical bars.\n",
      "    \n",
      "            (default: gray)\n",
      "    \n",
      "        hatch_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        hatch_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The hatch color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        hatch_extra (:class:`~bokeh.core.properties.Dict` ( :class:`~bokeh.core.properties.String` , :class:`~bokeh.core.properties.Instance` ( :class:`~bokeh.models.textures.Texture`  ) )):\n",
      "            The hatch extra values for the vertical bars.\n",
      "    \n",
      "            (default: {})\n",
      "    \n",
      "        hatch_pattern (:class:`~bokeh.core.properties.HatchPatternSpec` ):\n",
      "            The hatch pattern values for the vertical bars.\n",
      "    \n",
      "        hatch_scale (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch scale values for the vertical bars.\n",
      "    \n",
      "            (default: 12.0)\n",
      "    \n",
      "        hatch_weight (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch weight values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_cap (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineCap`  ), optional):\n",
      "            The line cap values for the vertical bars.\n",
      "    \n",
      "            (default: butt)\n",
      "    \n",
      "        line_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The line color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        line_dash (:class:`~bokeh.core.properties.DashPattern` ):\n",
      "            The line dash values for the vertical bars.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "        line_dash_offset (:class:`~bokeh.core.properties.Int` ):\n",
      "            The line dash offset values for the vertical bars.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "        line_join (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineJoin`  ), optional):\n",
      "            The line join values for the vertical bars.\n",
      "    \n",
      "            (default: bevel)\n",
      "    \n",
      "        line_width (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line width values for the vertical bars.\n",
      "    \n",
      "            (default: 1)\n",
      "    \n",
      "        name (:class:`~bokeh.core.properties.String` ):\n",
      "            An arbitrary, user-supplied name for this model.\n",
      "        \n",
      "            This name can be useful when querying the document to retrieve specific\n",
      "            Bokeh models.\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> plot.circle([1,2,3], [4,5,6], name=\"temp\")\n",
      "                >>> plot.select(name=\"temp\")\n",
      "                [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any names\n",
      "                that are provided, nor is the name used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "        tags (:class:`~bokeh.core.properties.List` ( :class:`~bokeh.core.properties.Any`  )):\n",
      "            An optional list of arbitrary, user-supplied values to attach to this\n",
      "            model.\n",
      "        \n",
      "            This data can be useful when querying the document to retrieve specific\n",
      "            Bokeh models:\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> r = plot.circle([1,2,3], [4,5,6])\n",
      "                >>> r.tags = [\"foo\", 10]\n",
      "                >>> plot.select(tags=['foo', 10])\n",
      "                [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]\n",
      "        \n",
      "            Or simply a convenient way to attach any necessary metadata to a model\n",
      "            that can be accessed by ``CustomJS`` callbacks, etc.\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any tags\n",
      "                that are provided, nor are the tags used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "    \n",
      "    \n",
      "    Other Parameters:\n",
      "        alpha (float, optional) :\n",
      "            An alias to set all alpha keyword arguments at once. (default: None)\n",
      "    \n",
      "            Alpha values must be between 0 (fully transparent) and 1 (fully opaque).\n",
      "    \n",
      "            Any explicitly set values for ``line_alpha``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "        color (Color, optional) :\n",
      "            An alias to set all color keyword arguments at once. (default: None)\n",
      "    \n",
      "            Acceptable values for colors are described in the `Specifying Colors`_\n",
      "            section of the User's Guide.\n",
      "    \n",
      "            Any explicitly set values for ``line_color``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "            .. _Specifying Colors: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#specifying-colors\n",
      "    \n",
      "        legend_field (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in the Browser`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed *in JavaScript*, at the time time the Bokeh\n",
      "            content is rendered in the browser. If the data is subsequently updated,\n",
      "            the legend will automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in the Browser: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-browser\n",
      "    \n",
      "        legend_group (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in Python`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed in Python, before the Bokeh output is sent to\n",
      "            a browser. If the date is subsequently updated, the legend will *not*\n",
      "            automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in Python: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-python\n",
      "    \n",
      "        legend_label (str, optional) :\n",
      "            Specify that the glyph should produce a single `Basic Legend Label`_ in\n",
      "            the legend. The legend entry is labeled with exactly the text supplied\n",
      "            here.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Basic Legend Label: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#basic-legend-label\n",
      "    \n",
      "        muted (bool, optionall) :\n",
      "            Whether the glyph should be rendered as muted (default: False)\n",
      "    \n",
      "            For this to be useful, an ``muted_glyph`` must be configured on the\n",
      "            returned ``GlyphRender``. This can be done by explicitly creating a\n",
      "            ``Glyph`` to use, or more simply by passing e.g. ``muted_color``, etc.\n",
      "            to this glyph function.\n",
      "    \n",
      "        name (str, optional) :\n",
      "            An optional user-supplied name to attach to the renderer (default: None)\n",
      "    \n",
      "            Bokeh does not use this value in any way, but it may be useful for\n",
      "            searching a Bokeh document to find a specific model.\n",
      "    \n",
      "        source (ColumnDataSource, optional) :\n",
      "            A user-supplied data source. (defatult: None)\n",
      "    \n",
      "            If not supplied, Bokeh will automatically construct an internal\n",
      "            ``ColumnDataSource`` with default column names from the coordinates and\n",
      "            other arguments that were passed-in as literal list or array values.\n",
      "    \n",
      "            If supplied, Bokeh will use the supplied data source to drive the glyph.\n",
      "            In this case, literal list or arrays may not be used for coordinates or\n",
      "            other arguments. Only singular fixed valued (e.g. ``x=10``) or column\n",
      "            names in the data souce (e.g. ``x=\"time\"``) are permitted.\n",
      "    \n",
      "        view (CDSView, optional) :\n",
      "            A view for filtering the data source. (default: None)\n",
      "    \n",
      "        visible (bool, optional) :\n",
      "            Whether the glyph should be rendered. (default: True)\n",
      "    \n",
      "        x_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping x-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        y_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping y-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        level (RenderLevel, optional) :\n",
      "            Specify the render level order for this glyph.\n",
      "    \n",
      "    \n",
      "    \n",
      "    It is also possible to set the color and alpha parameters of extra glyphs for\n",
      "    selection, nonselection, hover, or muted. To do so, add the relevane prefix to\n",
      "    any visual parameter. For example, pass ``nonselection_alpha`` to set the line\n",
      "    and fill alpha for nonselect, or ``hover_fill_alpha`` to set the fill alpha for\n",
      "    hover. See the `Glyphs`_ section od the User's Guide for full details.\n",
      "    \n",
      "    .. _Glyphs: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#glyphs\n",
      "    \n",
      "    Returns:\n",
      "        :class:`~bokeh.models.renderers.GlyphRenderer`\n",
      "    \n",
      "    \n",
      "    Examples:\n",
      "    \n",
      "        .. bokeh-plot::\n",
      "            :source-position: above\n",
      "    \n",
      "            from bokeh.plotting import figure, output_file, show\n",
      "    \n",
      "            plot = figure(plot_width=300, plot_height=300)\n",
      "            plot.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1,2,3], color=\"#CAB2D6\")\n",
      "    \n",
      "            show(plot)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 常用检查方式\n",
    "help(p.vbar)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 水平柱状图\n",
    "- 绘制方法\n",
    "> hbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('right', 4), ('y', 3)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"d8ec74ef-99d8-41a1-9fba-3afb69f5a1ad\" data-root-id=\"1104\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"48586818-35da-4e9a-b54f-c7c3e866dda6\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1115\"}],\"center\":[{\"id\":\"1118\"},{\"id\":\"1122\"}],\"left\":[{\"id\":\"1119\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1140\"}],\"title\":{\"id\":\"1105\"},\"toolbar\":{\"id\":\"1130\"},\"x_range\":{\"id\":\"1107\"},\"x_scale\":{\"id\":\"1111\"},\"y_range\":{\"id\":\"1109\"},\"y_scale\":{\"id\":\"1113\"}},\"id\":\"1104\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"1155\"},\"ticker\":{\"id\":\"1116\"}},\"id\":\"1115\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"1137\"},\"glyph\":{\"id\":\"1138\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1139\"},\"selection_glyph\":null,\"view\":{\"id\":\"1141\"}},\"id\":\"1140\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1129\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"text\":\"\\u6c34\\u5e73\\u67f1\\u72b6\\u56feDemo\"},\"id\":\"1105\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1107\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1157\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1111\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1113\",\"type\":\"LinearScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1123\"},{\"id\":\"1124\"},{\"id\":\"1125\"},{\"id\":\"1126\"},{\"id\":\"1127\"},{\"id\":\"1128\"}]},\"id\":\"1130\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1155\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1126\",\"type\":\"SaveTool\"},{\"attributes\":{\"data\":{\"right\":[1,2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1156\"},\"selection_policy\":{\"id\":\"1157\"}},\"id\":\"1137\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1128\",\"type\":\"HelpTool\"},{\"attributes\":{\"source\":{\"id\":\"1137\"}},\"id\":\"1141\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1115\"},\"ticker\":null},\"id\":\"1118\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1156\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1116\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1119\"},\"dimension\":1,\"ticker\":null},\"id\":\"1122\",\"type\":\"Grid\"},{\"attributes\":{\"overlay\":{\"id\":\"1129\"}},\"id\":\"1125\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1120\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"green\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"green\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1139\",\"type\":\"HBar\"},{\"attributes\":{\"fill_color\":{\"value\":\"green\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"green\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1138\",\"type\":\"HBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1153\"},\"ticker\":{\"id\":\"1120\"}},\"id\":\"1119\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1127\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1109\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"PanTool\"}],\"root_ids\":[\"1104\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"48586818-35da-4e9a-b54f-c7c3e866dda6\",\"root_ids\":[\"1104\"],\"roots\":{\"1104\":\"d8ec74ef-99d8-41a1-9fba-3afb69f5a1ad\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1104"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p= figure(plot_width = 400, plot_height = 400,title=\"水平柱状图Demo\")\n",
    "\n",
    "# 绘制柱状图\n",
    "p.hbar(y=[1,2,3],\n",
    "       height=0.5,\n",
    "       left=0,\n",
    "       right=[1,2,2.5,3.7],\n",
    "       color=\"green\"\n",
    ")\n",
    "# 展示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 常用检查方式\n",
    "??p.hbar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 柱状图Demo1（Fruits Counts）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"90de5572-6c8f-45c9-b8de-a1a462326241\" data-root-id=\"1207\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"00b657f8-676c-43e5-a767-476f172ca712\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1218\"}],\"center\":[{\"id\":\"1220\"},{\"id\":\"1224\"}],\"left\":[{\"id\":\"1221\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1242\"}],\"title\":{\"id\":\"1208\"},\"toolbar\":{\"id\":\"1232\"},\"x_range\":{\"id\":\"1210\"},\"x_scale\":{\"id\":\"1214\"},\"y_range\":{\"id\":\"1212\"},\"y_scale\":{\"id\":\"1216\"}},\"id\":\"1207\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"source\":{\"id\":\"1239\"}},\"id\":\"1243\",\"type\":\"CDSView\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1225\"},{\"id\":\"1226\"},{\"id\":\"1227\"},{\"id\":\"1228\"},{\"id\":\"1229\"},{\"id\":\"1230\"}]},\"id\":\"1232\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1216\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1263\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1241\",\"type\":\"VBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1231\"}},\"id\":\"1227\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1228\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1222\",\"type\":\"BasicTicker\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1208\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1226\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"data\":{\"top\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1266\"},\"selection_policy\":{\"id\":\"1267\"}},\"id\":\"1239\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1231\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"1239\"},\"glyph\":{\"id\":\"1240\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1241\"},\"selection_glyph\":null,\"view\":{\"id\":\"1243\"}},\"id\":\"1242\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"start\":0},\"id\":\"1212\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1267\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1225\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1219\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1230\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1214\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1210\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1240\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1265\"},\"ticker\":{\"id\":\"1219\"}},\"id\":\"1218\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1218\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1220\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1229\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"1221\"},\"dimension\":1,\"ticker\":null},\"id\":\"1224\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1265\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1263\"},\"ticker\":{\"id\":\"1222\"}},\"id\":\"1221\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1266\",\"type\":\"Selection\"}],\"root_ids\":[\"1207\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"00b657f8-676c-43e5-a767-476f172ca712\",\"root_ids\":[\"1207\"],\"roots\":{\"1207\":\"90de5572-6c8f-45c9-b8de-a1a462326241\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1207"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据准备（名称和值）\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=fruits,\n",
    "           plot_height=350,\n",
    "           title=\"Fruit Counts\",\n",
    "#            toolbar_location=None,\n",
    "#            tools=\"\"\n",
    ")\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x=fruits,\n",
    "       top=counts,\n",
    "       width=0.8\n",
    ")\n",
    "\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 柱状图Demo2（Fruits Counts）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"772fd72f-9fd6-4a6f-a825-cb1085cafd6d\" data-root-id=\"1318\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"648418ec-f069-4715-a0d1-1a008afc130f\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1329\"}],\"center\":[{\"id\":\"1331\"},{\"id\":\"1335\"}],\"left\":[{\"id\":\"1332\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1340\"}],\"title\":{\"id\":\"1319\"},\"toolbar\":{\"id\":\"1336\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1321\"},\"x_scale\":{\"id\":\"1325\"},\"y_range\":{\"id\":\"1323\"},\"y_scale\":{\"id\":\"1327\"}},\"id\":\"1318\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1325\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1371\"},\"ticker\":{\"id\":\"1330\"}},\"id\":\"1329\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1327\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1369\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1330\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1369\"},\"ticker\":{\"id\":\"1333\"}},\"id\":\"1332\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1371\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1333\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1332\"},\"dimension\":1,\"ticker\":null},\"id\":\"1335\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"1336\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"1329\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1331\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1372\"},\"selection_policy\":{\"id\":\"1373\"}},\"id\":\"1317\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1338\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"1317\"},\"glyph\":{\"id\":\"1338\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1339\"},\"selection_glyph\":null,\"view\":{\"id\":\"1341\"}},\"id\":\"1340\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1373\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1319\",\"type\":\"Title\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1339\",\"type\":\"VBar\"},{\"attributes\":{\"start\":0},\"id\":\"1323\",\"type\":\"DataRange1d\"},{\"attributes\":{\"source\":{\"id\":\"1317\"}},\"id\":\"1341\",\"type\":\"CDSView\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1321\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1372\",\"type\":\"Selection\"}],\"root_ids\":[\"1318\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"648418ec-f069-4715-a0d1-1a008afc130f\",\"root_ids\":[\"1318\"],\"roots\":{\"1318\":\"772fd72f-9fd6-4a6f-a825-cb1085cafd6d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1318"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "\n",
    "# 数据准备（名称和值）\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "\n",
    "# 数据源准备\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x = fruits,\n",
    "        counts = counts\n",
    "    )\n",
    ")\n",
    "TOOLTIPS = [\n",
    "    (\"count\",\"@counts\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=fruits,\n",
    "           plot_height=350,\n",
    "           title=\"Fruit Counts\",\n",
    "           toolbar_location=None,\n",
    "           tools=\"\"\n",
    ")\n",
    "\n",
    "# 绘制柱状图\n",
    "p.vbar(x=\"x\",\n",
    "       top=\"counts\",\n",
    "       width=0.8,\n",
    "       source=source\n",
    ")\n",
    "\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 实践（1）2019年7月常见可视化工具Github标星star数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"cd6bbe7f-5a2d-4931-b593-7e77ea0bb427\" data-root-id=\"1416\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"c9554ce9-7fb2-489f-8f85-faee23a2613d\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1427\"}],\"center\":[{\"id\":\"1429\"},{\"id\":\"1433\"}],\"left\":[{\"id\":\"1430\"}],\"renderers\":[{\"id\":\"1451\"}],\"title\":{\"id\":\"1417\"},\"toolbar\":{\"id\":\"1441\"},\"x_range\":{\"id\":\"1419\"},\"x_scale\":{\"id\":\"1423\"},\"y_range\":{\"id\":\"1421\"},\"y_scale\":{\"id\":\"1425\"}},\"id\":\"1416\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1438\",\"type\":\"ResetTool\"},{\"attributes\":{\"source\":{\"id\":\"1448\"}},\"id\":\"1452\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1490\",\"type\":\"Selection\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[9678,11034,5387,6038,4928,3783],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1490\"},\"selection_policy\":{\"id\":\"1491\"}},\"id\":\"1448\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"start\":0},\"id\":\"1421\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1450\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1423\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1448\"},\"glyph\":{\"id\":\"1449\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1450\"},\"selection_glyph\":null,\"view\":{\"id\":\"1452\"}},\"id\":\"1451\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1489\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1489\"},\"ticker\":{\"id\":\"1428\"}},\"id\":\"1427\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1487\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1425\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1449\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1419\",\"type\":\"FactorRange\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1434\"},{\"id\":\"1435\"},{\"id\":\"1436\"},{\"id\":\"1437\"},{\"id\":\"1438\"},{\"id\":\"1439\"}]},\"id\":\"1441\",\"type\":\"Toolbar\"},{\"attributes\":{\"formatter\":{\"id\":\"1487\"},\"ticker\":{\"id\":\"1431\"}},\"id\":\"1430\",\"type\":\"LinearAxis\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1417\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1491\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1428\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1440\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1431\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1434\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1435\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1427\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1429\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1439\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1440\"}},\"id\":\"1436\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1430\"},\"dimension\":1,\"ticker\":null},\"id\":\"1433\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1437\",\"type\":\"SaveTool\"}],\"root_ids\":[\"1416\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"c9554ce9-7fb2-489f-8f85-faee23a2613d\",\"root_ids\":[\"1416\"],\"roots\":{\"1416\":\"cd6bbe7f-5a2d-4931-b593-7e77ea0bb427\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1416"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "# 数据源\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "# 画布\n",
    "p = figure(x_range=df['Visualization_tools'],\n",
    "           title=\"2019年7月常见可视化工具Github标星数量\")\n",
    "\n",
    "# 绘制柱状图\n",
    "p.vbar(x=df['Visualization_tools'],\n",
    "       top=df['Star'] ,\n",
    "       width=0.8,\n",
    "       color=Spectral6\n",
    ") \n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 展示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " ### 第二种方法\n",
    " - 增加图例，设置图例等信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"a4298ef9-7ce3-4728-9cd1-5be5ef7a273f\" data-root-id=\"1542\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"5a95c9b4-e11c-4114-b5bd-0a3f44b6d198\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1553\"}],\"center\":[{\"id\":\"1555\"},{\"id\":\"1559\"},{\"id\":\"1589\"}],\"left\":[{\"id\":\"1556\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1579\"}],\"title\":{\"id\":\"1543\"},\"toolbar\":{\"id\":\"1568\"},\"x_range\":{\"id\":\"1545\"},\"x_scale\":{\"id\":\"1549\"},\"y_range\":{\"id\":\"1547\"},\"y_scale\":{\"id\":\"1551\"}},\"id\":\"1542\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"star_counts\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1586\"},\"selection_policy\":{\"id\":\"1587\"}},\"id\":\"1541\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1551\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1578\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1543\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1563\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1561\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@star_counts\"],[\"tools\",\"@tools\"]]},\"id\":\"1567\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1587\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1549\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1564\",\"type\":\"ResetTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1566\"}},\"id\":\"1562\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"end\":14000,\"start\":0},\"id\":\"1547\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1556\"},\"dimension\":1,\"ticker\":null},\"id\":\"1559\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1541\"}},\"id\":\"1580\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1585\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1585\"},\"ticker\":{\"id\":\"1554\"}},\"id\":\"1553\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"1583\"},\"ticker\":{\"id\":\"1557\"}},\"id\":\"1556\",\"type\":\"LinearAxis\"},{\"attributes\":{\"items\":[{\"id\":\"1590\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"1589\",\"type\":\"Legend\"},{\"attributes\":{\"data_source\":{\"id\":\"1541\"},\"glyph\":{\"id\":\"1577\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1578\"},\"selection_glyph\":null,\"view\":{\"id\":\"1580\"}},\"id\":\"1579\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1560\"},{\"id\":\"1561\"},{\"id\":\"1562\"},{\"id\":\"1563\"},{\"id\":\"1564\"},{\"id\":\"1565\"},{\"id\":\"1567\"}]},\"id\":\"1568\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1554\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1583\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1560\",\"type\":\"PanTool\"},{\"attributes\":{\"axis\":{\"id\":\"1553\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1555\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1545\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1565\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1557\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1577\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1586\",\"type\":\"Selection\"},{\"attributes\":{\"label\":{\"field\":\"tools\"},\"renderers\":[{\"id\":\"1579\"}]},\"id\":\"1590\",\"type\":\"LegendItem\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1566\",\"type\":\"BoxAnnotation\"}],\"root_ids\":[\"1542\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"5a95c9b4-e11c-4114-b5bd-0a3f44b6d198\",\"root_ids\":[\"1542\"],\"roots\":{\"1542\":\"a4298ef9-7ce3-4728-9cd1-5be5ef7a273f\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1542"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral6,Blues6\n",
    "# 数据源\n",
    "# 数据源准备\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        tools = df[\"Visualization_tools\"],\n",
    "        star_counts = df[\"Star\"],\n",
    "        color=Spectral6 # 坑，已解决\n",
    "    )\n",
    ")\n",
    "TOOLTIPS = [\n",
    "    (\"count\",\"@star_counts\"),\n",
    "    (\"tools\",\"@tools\")\n",
    "] \n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=df['Visualization_tools'],\n",
    "    plot_height = 350,\n",
    "    title=\"2019年7月常见可视化工具Github标星数量\",\n",
    "    tooltips = TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘制柱状图\n",
    "p.vbar(x='tools',\n",
    "       top='star_counts' ,\n",
    "       width=0.8,\n",
    "       color=\"color\",\n",
    "       source=source,\n",
    "       legend=\"tools\"   # 添加图例\n",
    ") \n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.y_range.end = 14000\n",
    "# 图例设置\n",
    "p.legend.location=\"top_center\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "\n",
    "# 展示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 实践（2）2019年7月常见可视化工具Github贡献者Contributors数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"299e22cc-7dd8-4b1a-b1de-21f41166044e\" data-root-id=\"1687\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"3e77d58f-6135-4ab5-8408-e4b283505070\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1698\"}],\"center\":[{\"id\":\"1700\"},{\"id\":\"1704\"}],\"left\":[{\"id\":\"1701\"}],\"renderers\":[{\"id\":\"1722\"}],\"title\":{\"id\":\"1688\"},\"toolbar\":{\"id\":\"1712\"},\"x_range\":{\"id\":\"1690\"},\"x_scale\":{\"id\":\"1694\"},\"y_range\":{\"id\":\"1692\"},\"y_scale\":{\"id\":\"1696\"}},\"id\":\"1687\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1776\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1721\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"1719\"}},\"id\":\"1723\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1777\",\"type\":\"Selection\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[808,357,18,98,76,184],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1777\"},\"selection_policy\":{\"id\":\"1778\"}},\"id\":\"1719\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"overlay\":{\"id\":\"1711\"}},\"id\":\"1707\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1705\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1778\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u6e90\\u7801Github\\u8d21\\u732e\\u8005\\u4eba\\u6570\"},\"id\":\"1688\",\"type\":\"Title\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1690\",\"type\":\"FactorRange\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1705\"},{\"id\":\"1706\"},{\"id\":\"1707\"},{\"id\":\"1708\"},{\"id\":\"1709\"},{\"id\":\"1710\"}]},\"id\":\"1712\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1708\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1699\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1698\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1700\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1709\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1719\"},\"glyph\":{\"id\":\"1720\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1721\"},\"selection_glyph\":null,\"view\":{\"id\":\"1723\"}},\"id\":\"1722\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"start\":0},\"id\":\"1692\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1701\"},\"dimension\":1,\"ticker\":null},\"id\":\"1704\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1720\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1696\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1694\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1776\"},\"ticker\":{\"id\":\"1699\"}},\"id\":\"1698\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"1774\"},\"ticker\":{\"id\":\"1702\"}},\"id\":\"1701\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1702\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1706\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1711\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1710\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1774\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"1687\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"3e77d58f-6135-4ab5-8408-e4b283505070\",\"root_ids\":[\"1687\"],\"roots\":{\"1687\":\"299e22cc-7dd8-4b1a-b1de-21f41166044e\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1687"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据源\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "# 画布\n",
    "p = figure(x_range=df['Visualization_tools'],\n",
    "           title=\"2019年7月常见可视化工具源码Github贡献者人数\")\n",
    "\n",
    "# 绘制柱状图\n",
    "p.vbar(x=df['Visualization_tools'],\n",
    "       top=df['Contributors'] ,\n",
    "       width=0.8,\n",
    "       color=Spectral6\n",
    ") \n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "\n",
    "# 展示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 实践（3）2019年7月常见可视化工具Github关注者Watch数量¶"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"e33081bf-32ef-4ba1-8138-05e627bff513\" data-root-id=\"1828\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"eaed97cf-f316-4c61-9bf1-25cbc55c9d39\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1839\"}],\"center\":[{\"id\":\"1841\"},{\"id\":\"1845\"}],\"left\":[{\"id\":\"1842\"}],\"renderers\":[{\"id\":\"1863\"}],\"title\":{\"id\":\"1829\"},\"toolbar\":{\"id\":\"1853\"},\"x_range\":{\"id\":\"1831\"},\"x_scale\":{\"id\":\"1835\"},\"y_range\":{\"id\":\"1833\"},\"y_scale\":{\"id\":\"1837\"}},\"id\":\"1828\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1927\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1835\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1861\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1923\"},\"ticker\":{\"id\":\"1843\"}},\"id\":\"1842\",\"type\":\"LinearAxis\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1846\"},{\"id\":\"1847\"},{\"id\":\"1848\"},{\"id\":\"1849\"},{\"id\":\"1850\"},{\"id\":\"1851\"}]},\"id\":\"1853\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1843\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1842\"},\"dimension\":1,\"ticker\":null},\"id\":\"1845\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1923\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1925\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1847\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1839\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1841\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1840\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1852\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1831\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1837\",\"type\":\"LinearScale\"},{\"attributes\":{\"start\":0},\"id\":\"1833\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[533,396,263,234,234,329],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1926\"},\"selection_policy\":{\"id\":\"1927\"}},\"id\":\"1860\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1862\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"1860\"}},\"id\":\"1864\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"1860\"},\"glyph\":{\"id\":\"1861\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1862\"},\"selection_glyph\":null,\"view\":{\"id\":\"1864\"}},\"id\":\"1863\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"1925\"},\"ticker\":{\"id\":\"1840\"}},\"id\":\"1839\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1846\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1926\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"1852\"}},\"id\":\"1848\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1850\",\"type\":\"ResetTool\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u6e90\\u7801Github\\u5173\\u6ce8\\u8005\\u4eba\\u6570\"},\"id\":\"1829\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1851\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1849\",\"type\":\"SaveTool\"}],\"root_ids\":[\"1828\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"eaed97cf-f316-4c61-9bf1-25cbc55c9d39\",\"root_ids\":[\"1828\"],\"roots\":{\"1828\":\"e33081bf-32ef-4ba1-8138-05e627bff513\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1828"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据源\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "# 画布\n",
    "p = figure(x_range=df['Visualization_tools'],\n",
    "           title=\"2019年7月常见可视化工具源码Github关注者人数\")\n",
    "\n",
    "# 绘制柱状图\n",
    "p.vbar(x=df['Visualization_tools'],\n",
    "       top=df['Watch'] ,\n",
    "       width=0.8,\n",
    "       color=Spectral6\n",
    ") \n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "\n",
    "# 展示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"701f45cc-9dd8-427d-b21f-db0cf44eaf5a\" data-root-id=\"2137\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"fc920e38-2ce1-4ca3-af54-e5a05fdf2ae9\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2147\"}],\"center\":[{\"id\":\"2149\"},{\"id\":\"2153\"}],\"left\":[{\"id\":\"2150\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"2171\"}],\"title\":{\"id\":\"2138\"},\"toolbar\":{\"id\":\"2161\"},\"x_range\":{\"id\":\"2136\"},\"x_scale\":{\"id\":\"2143\"},\"y_range\":{\"id\":\"2141\"},\"y_scale\":{\"id\":\"2145\"}},\"id\":\"2137\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2249\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"2249\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"2148\"}},\"id\":\"2147\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"2150\"},\"dimension\":1,\"ticker\":null},\"id\":\"2153\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"2135\"}},\"id\":\"2172\",\"type\":\"CDSView\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"2138\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2151\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2247\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"2160\"}},\"id\":\"2156\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2154\",\"type\":\"PanTool\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"2136\",\"type\":\"FactorRange\"},{\"attributes\":{\"axis\":{\"id\":\"2147\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"2149\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2158\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2251\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2145\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2148\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2155\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2250\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2159\",\"type\":\"HelpTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2154\"},{\"id\":\"2155\"},{\"id\":\"2156\"},{\"id\":\"2157\"},{\"id\":\"2158\"},{\"id\":\"2159\"}]},\"id\":\"2161\",\"type\":\"Toolbar\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"2250\"},\"selection_policy\":{\"id\":\"2251\"}},\"id\":\"2135\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2157\",\"type\":\"SaveTool\"},{\"attributes\":{\"start\":0},\"id\":\"2141\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"2247\"},\"ticker\":{\"id\":\"2151\"}},\"id\":\"2150\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2169\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"2135\"},\"glyph\":{\"id\":\"2169\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2170\"},\"selection_glyph\":null,\"view\":{\"id\":\"2172\"}},\"id\":\"2171\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2160\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2143\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2170\",\"type\":\"VBar\"}],\"root_ids\":[\"2137\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"fc920e38-2ce1-4ca3-af54-e5a05fdf2ae9\",\"root_ids\":[\"2137\"],\"roots\":{\"2137\":\"701f45cc-9dd8-427d-b21f-db0cf44eaf5a\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2137"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 学生实践检查（分组柱状图描述star,commits,contributes）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据准备：\n",
    "import pandas as pd\n",
    "pd.read_csv('data/visualization-20190505.csv')\n",
    "\n",
    "df = pd.read_csv('data/visualization-20190505.csv')\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Visualization_tools', 'Watch', 'Star', 'Fork', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Star', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group = [df.columns.tolist()[2],df.columns.tolist()[4],df.columns.tolist()[5]]\n",
    "group"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tools = df['Visualization_tools']\n",
    "tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('matplotlib', 'Star'),\n",
       " ('matplotlib', 'Commits'),\n",
       " ('matplotlib', 'Contributors'),\n",
       " ('bokeh', 'Star'),\n",
       " ('bokeh', 'Commits'),\n",
       " ('bokeh', 'Contributors'),\n",
       " ('pyecharts', 'Star'),\n",
       " ('pyecharts', 'Commits'),\n",
       " ('pyecharts', 'Contributors'),\n",
       " ('seaborn', 'Star'),\n",
       " ('seaborn', 'Commits'),\n",
       " ('seaborn', 'Contributors'),\n",
       " ('plotly', 'Star'),\n",
       " ('plotly', 'Commits'),\n",
       " ('plotly', 'Contributors'),\n",
       " ('ggplot2', 'Star'),\n",
       " ('ggplot2', 'Commits'),\n",
       " ('ggplot2', 'Contributors')]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = [ (tool, categroy) for tool in tools for categroy in group ]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(9678, 29503, 808, 11034, 17673, 357, 5387, 1321, 18, 6038, 2316, 98, 4928, 3370, 76, 3783, 4286, 184)\n"
     ]
    }
   ],
   "source": [
    "counts = sum(zip(df['Star'], df['Commits'], df['Contributors']), ())\n",
    "print(counts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "source = ColumnDataSource(data=dict(x=x, counts=counts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"b102c32e-1f90-48fd-baa4-662e7d7b7983\" data-root-id=\"3242\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"6dde0f43-0528-40db-a27f-40e74f78331f\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3252\"}],\"center\":[{\"id\":\"3254\"},{\"id\":\"3258\"}],\"left\":[{\"id\":\"3255\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"3278\"}],\"title\":{\"id\":\"3243\"},\"toolbar\":{\"id\":\"3267\"},\"x_range\":{\"id\":\"3241\"},\"x_scale\":{\"id\":\"3248\"},\"y_range\":{\"id\":\"3246\"},\"y_scale\":{\"id\":\"3250\"}},\"id\":\"3242\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"2424\"},\"selection_policy\":{\"id\":\"2425\"}},\"id\":\"2301\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3262\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"3380\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"2301\"}},\"id\":\"3279\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3259\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2424\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3263\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"3264\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3248\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"3265\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3276\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"3252\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3254\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"3255\"},\"dimension\":1,\"ticker\":null},\"id\":\"3258\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2425\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"3260\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"3256\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3253\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"3378\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"3380\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"3253\"}},\"id\":\"3252\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"3378\"},\"ticker\":{\"id\":\"3256\"}},\"id\":\"3255\",\"type\":\"LinearAxis\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"3243\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"3265\"}},\"id\":\"3261\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"2301\"},\"glyph\":{\"id\":\"3276\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3277\"},\"selection_glyph\":null,\"view\":{\"id\":\"3279\"}},\"id\":\"3278\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"3266\",\"type\":\"HoverTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3259\"},{\"id\":\"3260\"},{\"id\":\"3261\"},{\"id\":\"3262\"},{\"id\":\"3263\"},{\"id\":\"3264\"},{\"id\":\"3266\"}]},\"id\":\"3267\",\"type\":\"Toolbar\"},{\"attributes\":{\"start\":0},\"id\":\"3246\",\"type\":\"DataRange1d\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"3241\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"3250\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3277\",\"type\":\"VBar\"}],\"root_ids\":[\"3242\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"6dde0f43-0528-40db-a27f-40e74f78331f\",\"root_ids\":[\"3242\"],\"roots\":{\"3242\":\"b102c32e-1f90-48fd-baa4-662e7d7b7983\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3242"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "TOOLTIPS = [\n",
    "    (\"count\", \"@counts\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x),\n",
    "           plot_height=350,\n",
    "           title=\"Fruit Counts by Year\",\n",
    "           tooltips=TOOLTIPS\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"30bba4a2-1bac-4018-99d6-98e4e30b18c4\" data-root-id=\"3242\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"f919934e-05b1-4375-9a2d-fa2547432764\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3252\"}],\"center\":[{\"id\":\"3254\"},{\"id\":\"3258\"}],\"left\":[{\"id\":\"3255\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"3278\"},{\"id\":\"3436\"}],\"title\":{\"id\":\"3243\"},\"toolbar\":{\"id\":\"3267\"},\"x_range\":{\"id\":\"3241\"},\"x_scale\":{\"id\":\"3248\"},\"y_range\":{\"id\":\"3246\"},\"y_scale\":{\"id\":\"3250\"}},\"id\":\"3242\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"2424\"},\"selection_policy\":{\"id\":\"2425\"}},\"id\":\"2301\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3262\",\"type\":\"SaveTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"3432\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3435\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3380\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"2301\"}},\"id\":\"3279\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3259\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2424\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3263\",\"type\":\"ResetTool\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"3432\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3434\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3264\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3248\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"3265\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3276\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"3252\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3254\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"3255\"},\"dimension\":1,\"ticker\":null},\"id\":\"3258\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2425\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"3260\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"3256\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3253\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"2301\"},\"glyph\":{\"id\":\"3434\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3435\"},\"selection_glyph\":null,\"view\":{\"id\":\"3437\"}},\"id\":\"3436\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"2301\"}},\"id\":\"3437\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3378\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"3380\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"3253\"}},\"id\":\"3252\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"3378\"},\"ticker\":{\"id\":\"3256\"}},\"id\":\"3255\",\"type\":\"LinearAxis\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"3243\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"3265\"}},\"id\":\"3261\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"2301\"},\"glyph\":{\"id\":\"3276\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3277\"},\"selection_glyph\":null,\"view\":{\"id\":\"3279\"}},\"id\":\"3278\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"3266\",\"type\":\"HoverTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3259\"},{\"id\":\"3260\"},{\"id\":\"3261\"},{\"id\":\"3262\"},{\"id\":\"3263\"},{\"id\":\"3264\"},{\"id\":\"3266\"}]},\"id\":\"3267\",\"type\":\"Toolbar\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"red\",\"green\",\"blue\"],\"start\":1},\"id\":\"3432\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{\"start\":0},\"id\":\"3246\",\"type\":\"DataRange1d\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"3241\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"3250\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3277\",\"type\":\"VBar\"}],\"root_ids\":[\"3242\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"f919934e-05b1-4375-9a2d-fa2547432764\",\"root_ids\":[\"3242\"],\"roots\":{\"3242\":\"30bba4a2-1bac-4018-99d6-98e4e30b18c4\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3242"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 增加分组柱状图颜色\n",
    "from bokeh.transform import factor_cmap\n",
    "palette = [\"red\", \"green\", \"blue\"]\n",
    "\n",
    "# 绘图\n",
    "p.vbar(x='x',\n",
    "       top='counts',\n",
    "       width=0.9,\n",
    "       source=source,\n",
    "       line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=group, start=1, end=2)\n",
    ")\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "164.988px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
